package org.example.business.endpoint.http;

import io.netty.channel.ChannelHandlerContext;
import lombok.Data;

import java.net.InetSocketAddress;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

@Data
public class HttpSocket {

    public enum State{
        Connecting, Connected, Closing, Closed;

    }

    private State state;
    private String socketKey;
    private ChannelHandlerContext socketContext;
    private Map<String, String> messageMap = new ConcurrentHashMap<>();

    public HttpSocket(ChannelHandlerContext context){
        this.socketKey = createSocketKey(context);
        this.socketContext = context;

    }

    public static String buildKey(String ip, String port){
        return ip + ":" + port;

    }

    private String createSocketKey(ChannelHandlerContext ctx){
        InetSocketAddress remoteAddress = (InetSocketAddress) ctx.channel().remoteAddress();
        return buildKey(remoteAddress.getAddress().getHostAddress(), "" + remoteAddress.getPort());

    }

    public String toString(){
        return socketKey;

    }

}
